import React from 'react';
import { 
  FiTrendingUp, FiPieChart, FiBarChart2, FiDollarSign, 
  FiShield, FiLock, FiSettings, FiDatabase, 
  FiCode, FiCpu, FiAward, FiActivity, FiTool,
  FiFileText, FiTarget, FiList, FiRefreshCw, FiUsers,
  FiBriefcase, FiMonitor, FiEye, FiAlertTriangle, FiStar,
  FiPlusCircle, FiZap, FiUser, FiHeart, FiFilter,
  FiTag, FiRepeat, FiRss,FiLink
} from 'react-icons/fi';
import './Sidebar.css';

const Sidebar = ({ visible, activePage, onNavClick }) => {
  const handleSubItemClick = (subItemId) => {
    if (onNavClick) {
      onNavClick(activePage, subItemId);
    } else {
      // 默认跳转逻辑（如果 onNavClick 未定义）
      window.location.href = `/${activePage}/${subItemId}`;
    }
  };



  if (!visible) return null;

  const navGroups = {
    'market-review': [
      {
        title: '市场-整体环境',
        items: [
          { id: 'market-performance', label: '大盘环境', icon: <FiBarChart2 /> },
          { id: 'energy-center', label: '能量中心', icon: <FiTarget /> },
          { id: 'market-structure', label: '主线结构', icon: <FiPieChart /> },
          { id: 'market-money-abnormal', label: '资金异动', icon: <FiTool /> },
        ],
      },
      {
        title: '市场-资金情绪',
        items: [
          { id: 'policy-news', label: '政策消息', icon: <FiFileText /> },
          { id: 'profit-effect', label: '赚钱效应', icon: <FiDollarSign /> },
          { id: 'hotspot-theme', label: '热点题材', icon: <FiList /> },
          { id: 'sentiment-cycle', label: '情绪周期', icon: <FiRefreshCw /> },
        ],
      },
      {
        title: '操盘-交易模式',
        items: [
          { id: 'wave-profit', label: '波段复利', icon: <FiFilter /> },
          { id: 'main-leader-stock', label: '主线龙头', icon: <FiAward /> },
          { id: 'speculative-arbitrage', label: '投机套利', icon: <FiTrendingUp /> },
          { id: 'value-low-absorption', label: '价值低吸', icon: <FiTrendingUp /> },
        ],
      },
      {
        title: '操盘-账户管理',
        items: [
          { id: 'account-curve', label: '账户曲线', icon: <FiTrendingUp /> },
          { id: 'position-management', label: '仓位管理', icon: <FiActivity /> },
        ],
      },
    ],
    'real-time': [
      {
        title: '盘面',
        items: [
          { id: 'real-time-board', label: '实时盘面', icon: <FiMonitor /> },
          
        ],
      },
      {
        title: '买点信号',
        items: [
          { id: 'strategy-selection', label: '模式内自选', icon: <FiStar /> },
          { id: 'position-control', label: '仓位管理', icon: <FiPlusCircle /> },
          // { id: 'ice-point-selection', label: '冰点卡位', icon: <FiPlusCircle /> },
        ],
      },
      {
        title: '卖点信号',
        items: [
          { id: 'asset-monitor', label: '持仓及仓位', icon: <FiEye /> },
          { id: 'risk-alert', label: '风险预警', icon: <FiAlertTriangle /> },
         
        ],
      },
      {
        title: '交易界面',
        items: [
          { id: 'auto-trading', label: '自动交易', icon: <FiZap /> },
          { id: 'manual-trading', label: '人工交易', icon: <FiUser /> },
        ],
      },
    ],
    'strategy': [
      {
        title: '原则与共识',
        items: [
          { id: 'trade-rule', label: '交易原则', icon: <FiFilter /> },
          { id: 'market-consensus', label: '市场共识', icon: <FiRepeat /> },
          // { id: 'drawdown-control', label: '回撤控制', icon: <FiActivity /> },
        ],
      },
      {
        title: '技术状态识别',
        items: [
          { id: 'state-wave', label: '波段复利', icon: <FiFilter /> },
          { id: 'state-leader', label: '主线龙头', icon: <FiAward /> },
          { id: 'state-arbitrage', label: '投机套利', icon: <FiTrendingUp /> },
          { id: 'state-value', label: '价值低吸', icon: <FiTrendingUp /> },
        ],
      },
      {
        title: '交易策略',
        items: [
          { id: 'stock-selection-strategy', label: '选股信号', icon: <FiFilter /> },
          { id: 'buy-strategy', label: '买入节点（求定）', icon: <FiDollarSign /> },
          { id: 'sell-strategy', label: '卖出标准（求变）', icon: <FiRepeat /> },
          { id: 'position-strategy', label: '仓位策略', icon: <FiPieChart /> },
        ],
      },
      
      {
        title: '操盘真经',
        items: [
          { id: 'concept', label: '概念篇', icon: <FiTarget /> },
          { id: 'mind-method', label: '心法篇', icon: <FiFileText /> },
          { id: 'feature', label: '特征篇', icon: <FiTag /> },
          { id: 'essay-set', label: '文章集', icon: <FiFileText /> },
        ],
      },
      
    ],
    'stock-finder':[
      {
        title: '个股图谱',
        items: [
          { id: 'stock-tags', label: '个股标签', icon: <FiTag /> },
          { id: 'capital-relations', label: '股东关联', icon: <FiLink /> },
          { id: 'hotspot-relations', label: '概念关联', icon: <FiTrendingUp /> },
          { id: 'history-feacture', label: '历史股性', icon: <FiTrendingUp /> },
        ],
      },
      {
        title: '行业研究',
        items: [
          { id: 'industry-segmentation', label: '行业细分', icon: <FiPieChart /> },
          { id: 'leading-stock-research', label: '头牌研究', icon: <FiAward /> },
        ],
      },
      {
        title: '题材概念',
        items: [
          { id: 'kaipanla-themes', label: '开盘啦题材', icon: <FiList /> },
          { id: 'tonghuashun-themes', label: '同花顺题材', icon: <FiFileText /> },
        ],
      }
    ],
    'training': [
      {
        title: '数据标注',
        items: [
          { id: 'data-labeling', label: '数据标注', icon: <FiTag /> },
        ],
      },
      {
        title: '模型训练',
        items: [
          { id: 'fine-tuning', label: '大模型微调', icon: <FiSettings /> },
          { id: 'model-backtest', label: '模型回测', icon: <FiRepeat /> },
        ],
      },
      {
        title: '行为模型',
        items: [
          { id: 'main-force-model', label: '主力操盘模型', icon: <FiCpu /> },
          { id: 'fund-model', label: '资金选择模型', icon: <FiDollarSign /> },
          { id: 'sentiment-model', label: '情绪周期模型', icon: <FiHeart /> },
        ],
      },
      {
        title: '智能体',
        items: [
          { id: 'news-analysis', label: '新闻热点', icon: <FiRss /> },
          { id: 'feature-analysis', label: '特征分析', icon: <FiBarChart2 /> },
          { id: 'trading-agent', label: '交易智能体', icon: <FiZap /> },
        ],
      },
    ],
  };

  return (
    <aside className="sidebar">
      <div className="sidebar-header">
        <h3>
          {activePage === 'market-review' && '市场复盘'}
          {activePage === 'real-time' && '实时交易'}
          {activePage === 'strategy' && '操盘策略'}
          {activePage === 'stock-finder' && '个股挖掘'}
          {activePage === 'training' && '模型训练'}
        </h3>
      </div>
      
      <nav className="sidebar-nav">
        {navGroups[activePage]?.map((group, index) => (
          <div key={`group-${index}`} className="sidebar-group">
            <span className="sidebar-section-title">{group.title}</span>
            {group.items.map(item => (
              <button
                key={item.id}
                className="sidebar-item"
                onClick={() => handleSubItemClick(item.id)}
              >
                <span className="sidebar-icon">{item.icon}</span>
                <span className="sidebar-label">{item.label}</span>
              </button>
            ))}
            {index < navGroups[activePage].length - 1 && <hr className="sidebar-divider" />}
          </div>
        ))}
      </nav>
      
      <div className="sidebar-footer">
        <div className="status-indicator">
          <div className="status-dot connected"></div>
          <span>数据库已连接</span>
        </div>
        <div className="status-indicator">
          <div className="status-dot active"></div>
          <span>实时数据更新</span>
        </div>
      </div>
    </aside>
  );
};

export default Sidebar;